package cn.tedu._06interceptor.base.config;

import cn.tedu._06interceptor.base.interceptors.MyInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //策略1:拦截所有请求;
        //registry.addInterceptor(new MyInterceptor())
        //        .addPathPatterns("/v1/**");

        //策略2:拦截指定一个或者多个请求,比如拦截登录请求和注册请求;
        //registry.addInterceptor(new MyInterceptor())
        //        .addPathPatterns("/v1/user/login", "/v1/user/reg");

        //策略3:拦截指定多个请求,比如拦截用户模块的所有请求;
        //registry.addInterceptor(new MyInterceptor())
        //        .addPathPatterns("/v1/user/**");

        //策略4:拦截指定多个请求,比如拦截用户模块的所有请求,但是不拦截登录请求;
        registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/v1/user/**")
                .excludePathPatterns("/v1/user/login");

        //多个拦截器执行顺序
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/v1/**");
//        registry.addInterceptor(new MyInterceptor2())
//                .addPathPatterns("/v1/**");
    }
}
